const Koa = require('koa');
const Router = require('koa-router');
const bodyParser = require('koa-bodyparser');

const app = new Koa();
const router = new Router();

router.get('/api/add', async (ctx, next) => {
  const query = ctx.query 
  console.log(query);  
  const a = Number(query.x);
  const b = Number(query.y);
  const result = a + b;
  ctx.body = {
    x: a,
    y: b,
    sum: result}; 
});

app.use(bodyParser());
app.use(router.routes());

app.listen(3000);
console.log('Server running at http://localhost:3000/');
